package cn.thoughtworks.school.repositories;

import cn.thoughtworks.school.entities.OnlineCodingQuiz;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface OnlineCodingQuizRepository extends JpaRepository<OnlineCodingQuiz, Long>,JpaSpecificationExecutor<OnlineCodingQuiz> {
    List<OnlineCodingQuiz> findByIdInAndIsAvailableIsTrue(List<Long> ids);

    List<OnlineCodingQuiz> findByOnlineCodingNameAndLanguageAndStatusOrderByCreateTimeDesc(String onlineCodingName, String language, int status);
    @Query(value = "SELECT  b FROM OnlineCodingQuiz b JOIN b.tags t WHERE  b.isAvailable=true AND t.name in :names")
    List<OnlineCodingQuiz> findQuizzesByTags(@Param("names") List<String> names);

    List<OnlineCodingQuiz> findByIdIn(List<Long> ids);

}
